namespace UnityX
{
    /// <summary>
    /// 配置文件类扩展功能
    /// </summary>
    public static class ConfigFileExtension
    {
        public static void SetColor(this CSharpX.ConfigFile configFile, string name, UnityEngine.Color color)
        {
            configFile.Set(name, new float[] { color.r, color.g, color.b, color.a });
        }
        public static void SetColor32(this CSharpX.ConfigFile configFile, string name, UnityEngine.Color32 color32)
        {
            configFile.Set(name, new byte[] { color32.r, color32.g, color32.b, color32.a });
        }
        public static void SetVector2(this CSharpX.ConfigFile configFile, string name, UnityEngine.Vector2 vector2)
        {
            configFile.Set(name, new float[] { vector2.x, vector2.y });
        }
        public static void SetVector3(this CSharpX.ConfigFile configFile, string name, UnityEngine.Vector3 vector3)
        {
            configFile.Set(name, new float[] { vector3.x, vector3.y, vector3.z });
        }
        public static void SetVector4(this CSharpX.ConfigFile configFile, string name, UnityEngine.Vector4 vector4)
        {
            configFile.Set(name, new float[] { vector4.x, vector4.y, vector4.z, vector4.w });
        }
        public static void SetQuaternion(this CSharpX.ConfigFile configFile, string name, UnityEngine.Quaternion quaternion)
        {
            configFile.Set(name, new float[] { quaternion.x, quaternion.y, quaternion.z, quaternion.w });
        }

        public static UnityEngine.Color GetColor(this CSharpX.ConfigFile configFile, string name, UnityEngine.Color defaultValue)
        {
            float[] vs = configFile.Get(name, new float[] { defaultValue.r, defaultValue.g, defaultValue.b, defaultValue.a });
            if (vs.Length != 4) return defaultValue;
            return new UnityEngine.Color(vs[0], vs[1], vs[2], vs[3]);
        }
        public static UnityEngine.Color32 GetColor32(this CSharpX.ConfigFile configFile, string name, UnityEngine.Color32 defaultValue)
        {
            byte[] vs = configFile.Get(name, new byte[] { defaultValue.r, defaultValue.g, defaultValue.b, defaultValue.a });
            if (vs.Length != 4) return defaultValue;
            return new UnityEngine.Color32(vs[0], vs[1], vs[2], vs[3]);
        }
        public static UnityEngine.Vector2 GetVector2(this CSharpX.ConfigFile configFile, string name, UnityEngine.Vector2 defaultValue)
        {
            float[] vs = configFile.Get(name, new float[] { defaultValue.x, defaultValue.y });
            if (vs.Length != 2) return defaultValue;
            return new UnityEngine.Vector2(vs[0], vs[1]);
        }
        public static UnityEngine.Vector3 GetVector3(this CSharpX.ConfigFile configFile, string name, UnityEngine.Vector3 defaultValue)
        {
            float[] vs = configFile.Get(name, new float[] { defaultValue.x, defaultValue.y, defaultValue.z });
            if (vs.Length != 3) return defaultValue;
            return new UnityEngine.Vector3(vs[0], vs[1], vs[2]);
        }
        public static UnityEngine.Vector4 GetVector4(this CSharpX.ConfigFile configFile, string name, UnityEngine.Vector4 defaultValue)
        {
            float[] vs = configFile.Get(name, new float[] { defaultValue.x, defaultValue.y, defaultValue.z, defaultValue.w });
            if (vs.Length != 4) return defaultValue;
            return new UnityEngine.Vector4(vs[0], vs[1], vs[2], vs[3]);
        }
        public static UnityEngine.Quaternion GetQuaternion(this CSharpX.ConfigFile configFile, string name, UnityEngine.Quaternion defaultValue)
        {
            float[] vs = configFile.Get(name, new float[] { defaultValue.x, defaultValue.y, defaultValue.z, defaultValue.w });
            if (vs.Length != 4) return defaultValue;
            return new UnityEngine.Quaternion(vs[0], vs[1], vs[2], vs[3]);
        }
    }
}